<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>考试试卷</title>
<link th:href="@{/css/webquestion/main.css}" rel="stylesheet" type="text/css" />
<link th:href="@{/css/webquestion/iconfont.css}" rel="stylesheet" type="text/css" />
<link th:href="@{/css/webquestion/test.css}" rel="stylesheet" type="text/css" />
<style>
.hasBeenAnswer {
	background: #5d9cec;
	color:#fff;
}
</style>
</head>
<body>
	<div class="main">
		<!--nr start-->
		<div class="test_main">
			<div class="nr_left">
				<div class="test">
					<form id="form1" action="##" onsubmit="return false" method="post">
						<input type="hidden" name="examId" id="examId" value="" />
						<div class="test_title">
							<font><input type="button" name="test_jiaojuan" value="交卷"></font>
						</div>
							<div class="test_content">
								<div class="test_content_title">
									<h2>单选题</h2>
									<p>
										<span>共</span><i class="content_lit" id="choose">60</i><span>题，</span><span>合计</span><i class="content_fs" id="choosescore">60</i><span>分</span>
									</p>
								</div>
							</div>
							<div class="test_content_nr">
								<ul id="chooseInfo">
									<!--<li id="qu_0_0">
										<div class="test_content_nr_tt">
											<i>1</i><span>(1分)</span><font>这里是试题这里是试题这里是试题这里是试题这里是试题这里是试题这里是试题这里是试题这里是试题</font><b class="icon iconfont">&#xe881;</b>
										</div>
										<div class="test_content_nr_main">
											<ul>
												<li class="option">
														<input type="radio" class="radioOrCheck" name="answer1"
															id="0_answer_1_option_1"
														/>
													<label for="0_answer_1_option_1">
														A.
														<p class="ue" style="display: inline;">这里是A答案这里是A答案这里是A答案这里是A答案这里是A答案</p>
													</label>
												</li>
												<li class="option">
														<input type="radio" class="radioOrCheck" name="answer1"
															id="0_answer_1_option_2"
														/>
													<label for="0_answer_1_option_2">
														B.
														<p class="ue" style="display: inline;">这里是B答案这里是B答案这里是B答案这里是B答案这里是B答案</p>
													</label>
												</li>
												<li class="option">
														<input type="radio" class="radioOrCheck" name="answer1"
															id="0_answer_1_option_3"
														/>
													<label for="0_answer_1_option_3">
														C.
														<p class="ue" style="display: inline;">这里是C答案这里是C答案这里是C答案这里是C答案这里是C答案</p>
													</label>
												</li>
											</ul>
										</div>
									</li>-->
								</ul>
							</div>
						<div class="test_content">
							<div class="test_content_title">
								<h2>判断题</h2>
								<p>
									<span>共</span><i class="content_lit" id="sumjudge"></i><span>题，</span><span>合计</span><i class="content_fs" id="judgescore"></i><span>分</span>
								</p>
							</div>
						</div>
						<div class="test_content_nr">
							<ul id="judgeInfo">
							</ul>
						</div>
					</form>
				</div>
			</div>
		</div>
		<!--nr end-->
		<div class="foot"></div>
	</div>
	<script th:src="@{/js/jquery.min.js}"></script>
	<script th:src="@{/css/webquestion/jquery.easy-pie-chart.js}"></script>
	<script>
		var ctx = "/";
		$(function() {
		    var eId = "[[${eid}]]";
		    $("#examId").val(eId);
		    //获取数据
			$.get(ctx+"exam/tTestquestion/qlist/"+eId,{},function (data) {
				if(data.length > 0) {
				    var choose = "";
				    var judge = "";
                    var jsumscore = 0;
                    var csumscore = 0;
                    var cnum = 1;//定义试题的前置编号
                    var jnum = 1;//定义试题的前置编号
                    for(var i=0;i<data.length;i++) {
						var type = data[i].qtype;//试题类型
						if(type === 1) {	//判断题
							var jscore = data[i].qscore;
                            jsumscore += jscore;	//计算题型总分
							var qname = data[i].qname;
							var qid = data[i].qid;
							judge += "<li id=\""+qid+"\">" +
                            	"<div class=\"test_content_nr_tt\">"+
                                "<i>"+jnum+"</i><span>("+jscore+"分)</span><font>"+qname+"</font><b class=\"icon iconfont\">&#xe881;</b>"+
                            	"</div>"+
                            	"<div class=\"test_content_nr_main\">"+
                                "<ul>";
							var answers = data[i].tAnswerList;
							for(var j=0;j<answers.length;j++) {
							    var sname = answers[j].sname;
							    var sid = answers[j].sid;
								judge += "<li class=\"option\">"+
                                	"<input type=\"radio\" class=\"radioOrCheck\" name=\""+qid+"\" value=\""+sid+"\""+
                                	"id=\""+qid+"\""+
                                    "/>"+
                                    "<label for=\""+qid+"\">"+
                                    "<p class=\"ue\" style=\"display: inline;\">"+sname+"</p>"+
                                    "</label>"+
                                    "</li>";
							}
                            judge += "</ul>"+
                                "</div>";
							jnum++;
							continue;
						} else {
                            var cscore = data[i].qscore;
                            csumscore += cscore;	//计算题型总分
                            var qname = data[i].qname;
                            var qid = data[i].qid;
                            choose += "<li id=\""+qid+"\">" +
                                "<div class=\"test_content_nr_tt\">"+
                                "<i>"+cnum+"</i><span>("+jscore+"分)</span><font>"+qname+"</font><b class=\"icon iconfont\">&#xe881;</b>"+
                                "</div>"+
                                "<div class=\"test_content_nr_main\">"+
                                "<ul>";
                            var answers = data[i].tAnswerList;
                            for(var j=0;j<answers.length;j++) {
                                var sname = answers[j].sname;
                                var sid = answers[j].sid;
                                choose += "<li class=\"option\">"+
                                    "<input type=\"radio\" class=\"radioOrCheck\" name=\""+qid+"\" value=\""+sid+"\""+
                                    "id=\""+qid+"\""+
                                    "/>"+
                                    "<label for=\""+qid+"\">"+
                                    "<p class=\"ue\" style=\"display: inline;\">"+sname+"</p>"+
                                    "</label>"+
                                    "</li>";
                            }
                            choose += "</ul>"+
                                "</div>";
                            cnum++;
						}
					}
                    $("#chooseInfo").html(choose);
                    $("#choose").text(cnum-1);
                    $("#choosescore").text(cscore);
					$("#judgeInfo").html(judge);
                    $("#judgescore").text(jsumscore);
                    $("#sumjudge").text(jnum-1);
				}
            });
		});

        /**
		 * 试卷提交
         */
		$("input:button").click(function(){
		    //获取选择题的所有name值
			var jsonData = {};
		    var chooseli = $("#chooseInfo").children();
		    for(var i=0;i<chooseli.length;i++) {
				var liid = chooseli[i].getAttribute("id");
				if(null != liid && "" != liid) {
                    var val=$('input:radio[name=\"'+liid+'\"]:checked').val();
                    if(undefined == val || null == val || "" == val) {
						alert("选择题第"+(i+1)+"道题还没选择！");
                        jsonData = {};
						return ;
					}
                    //var oneans = {liid:val};
                    jsonData[liid] = val;
				}
			}
			//获取判断题的所有name值
			var judgeli = $("#judgeInfo").children();
            for(var i=0;i<judgeli.length;i++) {
                var liid = judgeli[i].getAttribute("id");
                if(null != liid && "" != liid) {
                    var val=$('input:radio[name=\"'+liid+'\"]:checked').val();
                    console.log(liid+":"+val);
                    if(undefined == val || null == val || "" == val) {
                        alert("判断题第"+(i+1)+"道题还没选择！");
                        jsonData = {};
                        return ;
                    }
                    jsonData[liid] = val;
                    jsonData["examId"] = $("#examId").val();;
                }
            }
            console.log(jsonData);
			$.ajax({
			    type: "POST",
                dataType: "json",//预期服务器返回的数据类型
                url: "/teach/exam/sumScore" ,//url
                data: JSON.stringify(jsonData),
                contentType : "application/json",
                success: function (result) {
					console.log(result);//打印服务端返回的数据(调试用)
					if(result.code === 0) {
						alert(result.msg);
                        window.location.href=ctx+"web/toExamList";
					} else {
                        alert("异常！");
					}
				},
				error : function() {
					alert("异常！");
				}
            });

		})
	</script>
</body>
</html>